package cloneExample;

import com.google.gson.Gson;
import org.apache.commons.lang3.SerializationUtils;

/**
 * 利用 Google的JSON转换工具Gson 来copy对象
 */
public class CloneExample5 {
	public static void main(String[] args) {
		cloneByJSON();
	}

	private static void cloneByJSON() {
		Address address = new Address(110,"beijing");
		People p1 = new People(1, "Java", address);
		Gson gson = new Gson();
		String tempJson = gson.toJson(p1);
		People p2 = gson.fromJson(tempJson, People.class);


		p1.getAddress().setCity("guangzhou");
		// 两个内容不一致，说明了是两个对象。
		System.out.println("p1:" + p1.getAddress().getCity()); // guangzhou
		System.out.println("p2:" + p2.getAddress().getCity()); // beijing
	}
}
